package com.xiaoyu.chap3.GC;

/**
 * Created by xiaoyu on 16/4/4.
 *
 * VM args:-XX:+PrintGC
 * testGC()执行后，objA和objB会不会被GC呢？
 */
public class ReferenceCountingGC {

    public Object instance = null;
    private static final int _1MB = 1024*1024;

    //搞个成员占点内存
    private byte[] bigSize = new byte[2*_1MB];

    public static void testGC(){
        ReferenceCountingGC objA = new ReferenceCountingGC();
        ReferenceCountingGC objB = new ReferenceCountingGC();
        objA.instance = objB;
        objB.instance = objA;
        objA = null;
        objB = null;

        System.gc();
    }

    public static void main(String[] args) {
        ReferenceCountingGC.testGC();
    }

}
